Ext.onReady(function(){

var store = Ext.create('Ext.data.Store', {
	autoLoad:false,
	pageSize: 20,
	groupField: 'requestNo',
	fields: [{name:'orderId'},{name:'requestNo'},{name:'clientUniqueId'},{name:'modelName'},{name:'project'},{name:'product'},{name:'customer'},
			{name:'status'},{name:'temp'},{name:'amount'}],
	proxy: {
		type: 'ajax',
		url: 'getPipeline.action',
		extraParams:{modelId:getURLParameter('modelId')},
		reader: {
			type: 'json',
			root: 'items',
			totalProperty: 'size'
		}
	}
});

var bbar = new Ext.PagingToolbar({  
	store: store,  
	displayInfo: true,
	prependButtons: true,  
	displayMsg : 'Record {0} ~ {1}, Total: {2}',     
	emptyMsg : "No Record",
	doLoad:function(start){  
	}  
});

pipelineGrid = Ext.create('Ext.grid.Panel',{
		id:'pipelineGrid',
		autoScroll:false,
		enableColumnHide:false,
		enableColumnResize:false,
		sortableColumns:false,
		columnLines:true,
		enableColumnMove:false,
		multiSelect:true,
		//selModel:Ext.create('Ext.selection.CheckboxModel'),
		height:Ext.getBody().getHeight()-165,
		forceFit:true,
		/*plugins: Ext.create('Ext.grid.plugin.CellEditing', {
			clicksToEdit: 1,
			listeners:{
				beforeedit:function(obj,eOpts){
					if(eOpts.record.data.status!='Green Status'){
						return false;
					}
					return true;
				}
			}
		}),*/
		columns:[{
			text:'Status',
			dataIndex:'status',
			minWidth:60,
			renderer: columnWrap
		},{
			text:'Model Name',
			dataIndex:'modelName',
			minWidth:40,
			renderer: columnWrap
		},{
			text:'TRP Number',
			dataIndex:'requestNo',
			minWidth:60,
			renderer: columnWrap
		},{
			text:'Customer',
			minWidth:80,
			dataIndex:'customer'
		},{
			text:'Project',
			dataIndex:'project',
			minWidth:80
		},{
			text:'Product',
			minWidth:80,
			dataIndex:'product'
		},{
			text:'Temperature',
			dataIndex:'temp',
			minWidth:100
		},{
			text:'Test Type',
			minWidth:80,
			dataIndex:'modelName'
		},{
			text:'Amount',
			dataIndex:'amount',
			minWidth:80
		},{
			text:'Test Request',
			minWidth:80,
			renderer: function(value,a,obj,idx){
				return '<a href="viewOrder.action?orderId='+obj.data.orderId+'" target="_blank">view detail</a>';
			}
		},{
			text:'Action',
			width:60,
			renderer:function(value,cellmeta,record,rowIndex,columnIdx,store){
				if(true){
					return '<a href="javascript:changeStatus('+record.data.orderId+',\''+record.data.clientUniqueId+'\')">Change<br>Status</a>';
				}else{
					
				}
			}
		}],
		store: store,
		bbar: bbar/*,
		viewConfig: {
			listeners:{
				'beforecellmousedown':function(view, cell, cellIdx, record, row, rowIdx, eOpts){
					return false;
				}
			}
		},
		listeners:{
			'itemclick':function(view, record, item, index, e, eOpts){
				if(this.getSelectionModel().isSelected(record)){
					this.getSelectionModel().deselect(record,true);
				}else{
					if(record.data.status=='Green Status'){
						this.getSelectionModel().select(record,true);
					}	
				}	
			}
		}*/
	});
	pipelineGrid.getView().on('afterrender',function(){pipelineGrid.getEl().mask('loading...');});
	pipelineGrid.getView().on('refresh',function(){pipelineGrid.getEl().unmask();});
	store.on('beforeload', function (store, options) {
        var new_params = { status: Ext.getCmp('txtStatus').getValue(), addCriteria: Ext.getCmp('addCriteria').getValue(), addValue:Ext.getCmp('addValue').getValue()};
        Ext.apply(store.proxy.extraParams, new_params);
    });
	store.loadPage(1);
	pipelineGrid.getView().refresh();
	
	Ext.getCmp('pipelinePnl').add(pipelineGrid);
});
